package cobra0

import (
	"fmt"
	"github.com/spf13/cobra"
)

//定义根命令命令
var rootCmd = &cobra.Command{
	//
	Use: "my-git",
	//命令的长短帮助描述
	Short: "Git is a distributed version control system.",
	Long: `Git is a free and open source distributed version control system
designed to handle everything from small to very large projects
with speed and efficiency.`,
	//根命令的运行逻辑
	Run: func(cmd *cobra.Command, args []string) {
		//Error(cmd, args, errors.New("unrecognized command"))
		fmt.Println(cmd, args)

	},
}

var Verbose bool
var Source string

func Execute() {
	//cobra 中选项分为两种，
	//一种是永久选项，定义它的命令和其子命令都可以使用。通过给根命令添加一个选项定义全局选项。
	//另一种是本地选项，只能在定义它的命令中使用。

	//设置永久选项
	rootCmd.PersistentFlags().BoolVarP(&Verbose, "verbose", "v", false, "verbose output")

	rootCmd.Execute()
}
